<?php
// 【最终版】m-merchant/commission.php
require_once('common/header.php'); 
?>
<style>
    .page-title-bar { padding: 1rem; border-bottom: 1px solid #f0f0f0; display: flex; align-items: center; background-color: #fff;}
    .page-title-bar .back-btn { font-size: 1.5rem; color: #333; text-decoration: none; margin-right: 1rem;}
    .page-title-bar h4 { margin: 0; font-weight: 600; }
</style>

<div id="commission-app" v-cloak>
    <div class="page-title-bar">
        <a href="profile.php" class="back-btn"><i class="bi bi-arrow-left"></i></a>
        <h4>全局佣金设置</h4>
    </div>

    <div class="main-content">
        <div class="card">
            <div class="card-body">
                <div v-if="isLoading" class="text-center p-5"><div class="spinner-border"></div></div>
                <div v-else>
                    <p class="text-muted small">您在这里设置的规则，将自动应用于您名下所有直属下级代理的订单佣金。</p>
                    <div id="alert-container" class="my-3"></div>
                    <form id="commission-form" @submit.prevent="saveCommission">
                        <div class="mb-3">
                            <label class="form-label fw-bold">抽成类型</label>
                            <select name="commission_type" class="form-select form-select-lg" v-model="form.type">
                                <option value="0">不抽成</option>
                                <option value="1">固定金额</option>
                                <option value="2">百分比</option>
                            </select>
                        </div>
                        <div class="mb-4">
                            <label class="form-label fw-bold">抽成数值</label>
                            <input type="number" step="0.01" class="form-control form-control-lg" name="commission_value" v-model="form.value" placeholder="输入数值" required>
                            <div class="form-text">固定金额填 5.00；百分比填 10 代表10%。</div>
                        </div>
                        <button type="submit" class="btn btn-primary w-100 btn-lg" :disabled="isSubmitting">
                            {{ isSubmitting ? '保存中...' : '保存规则' }}
                        </button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<?php require_once('common/footer.php'); ?>